package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.AccountCriteria;
import com.leo.ibatis.demo.dao.AccountDao;
import com.leo.ibatis.demo.domain.Account;
import com.leo.ibatis.demo.service.AccountService;

public class AccountServiceImpl extends Service implements AccountService {

	private AccountDao accountDao;

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	public void insert(Account account) {
		accountDao.insert(account);
	}

	public int update(Account account) {
		int actualRowsAffected = 0;
		
		String userid = account.getUserid();

		Account _oldAccount = accountDao.select(userid);
		
		if (_oldAccount != null) {
			actualRowsAffected = accountDao.update(account);
		}
		
		return actualRowsAffected;
	}

	public int delete(String userid) {
		int actualRowsAffected = 0;
		
		Account _oldAccount = accountDao.select(userid);
		
		if (_oldAccount != null) {
			actualRowsAffected = accountDao.delete(userid);
		}
		
		return actualRowsAffected;
	}
	
	public Account select(String userid) {
		return accountDao.select(userid);
	}

	public List<Account> list(AccountCriteria accountCriteria) {
		return accountDao.list(accountCriteria);
	}
	
	public List<Account> listOnPage(AccountCriteria accountCriteria) {
		return accountDao.listOnPage(accountCriteria);
	}

}
